package com.dt76.smallloanbackendservice.controller.afterloan;


import com.dt76.smallloanbackendservice.pojo.afterloan.EWQualification;
import com.dt76.smallloanbackendservice.pojo.afterloan.EarlyWarningInfo;
import com.dt76.smallloanbackendservice.service.afterloan.EarlyWarningService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
public class EarlyWarningController {

    private final EarlyWarningService earlyWarningService;

    public EarlyWarningController(EarlyWarningService earlyWarningService) {
        this.earlyWarningService = earlyWarningService;
    }

    //对预警信息执行修改操作
    @PostMapping("/earlyWarning/jumpToEarlyEdit")
    public Integer jumpToEarlyEdit(@RequestBody EarlyWarningInfo form) {
        return earlyWarningService.modifyInfo(form);
    }

    //获取分页的预警信息
    @PostMapping("/earlyWarning/getPageEWList")
    public Map<String,Object> getPageEWList(@RequestBody EWQualification q, Integer currentPage, Integer pageSize) {
        Map<String, Object> map = new HashMap<>();
        List<EarlyWarningInfo> lists = earlyWarningService.getPageList(currentPage, pageSize, q);
        map.put("list",lists);
        map.put("total",earlyWarningService.getCount(q));
        return map;
    }

    //根据ID查询预警信息
    @RequestMapping("/earlyWarning/getById")
    public Map<String, Object> getById( String id){
        Map<String,Object> map = new HashMap<>();
        map.put("ew",earlyWarningService.getById(id));
        return map;
    }

    @PostMapping("/earlyWarning/addEW")
    public Map<String, Object> addEW(@RequestBody EarlyWarningInfo form){
        Map<String,Object> map = new HashMap<>();
        Integer res = earlyWarningService.addNew(form);
        map.put("res",res);
        return map;
    }

}
